package com.singerw.controller;

import com.alibaba.fastjson.JSONObject;
import com.singerw.annotations.OperLog;
import com.singerw.annotations.ResponseResult;
import com.singerw.pojo.TwOptions;
import com.singerw.service.TwOptionsService;
import com.singerw.service.oss.OSSService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @version V1.0
 * @Package com.singerw.controller
 * @auhter 张欣
 * @date 2021/1/23-3:59 PM
 */
@RestController
@RequestMapping("/option")
public class OptionsController {
    @Autowired
    private TwOptionsService twOptionsService;
    @Autowired
    private OSSService ossService;
    @PostMapping("/notice/add")
    @ResponseResult
    @OperLog(operModul = "设置模块",operType = "发布公告",operDesc = "后台发布公告")
    public void addNotice(@RequestBody JSONObject jsonObject) {
        twOptionsService.save(new TwOptions("notice", jsonObject.toJSONString()));
    }
    @GetMapping("/notice/remove")
    @ResponseResult
    @OperLog(operModul = "设置模块",operType = "删除公告",operDesc = "后台删除公告")
    public void removeNotice() {
        twOptionsService.remove("notice");
    }
    @GetMapping("/notice/get")
    @ResponseResult
    public TwOptions getNotice() {
        return twOptionsService.findByName("notice");
    }

    @GetMapping("/OSSConfig/get")
    @ResponseResult
    public TwOptions getOSSConfig(){
        return twOptionsService.findByName("oss_configure");
    }
    @PostMapping("/OSSConfig/set")
    @ResponseResult
    @OperLog(operModul = "设置模块",operType = "OSS配置修改",operDesc = "后台修改OSS配置")
    public void setOSSConfig(@RequestBody JSONObject jsonObject) {
        twOptionsService.save(new TwOptions("oss_configure", jsonObject.toJSONString()));
        ossService.updateConfigure();
    }
    @GetMapping("/routine/get")
    @ResponseResult
    public TwOptions getRoutineConfig(){
        return twOptionsService.findByName("routine");
    }
    @PostMapping("/routine/set")
    @ResponseResult
    @OperLog(operModul = "设置模块",operType = "常规配置修改",operDesc = "后台修改常规配置")
    public void setRoutineConfig(@RequestBody JSONObject jsonObject) {
        twOptionsService.save(new TwOptions("routine", jsonObject.toJSONString()));
    }

}
